/**
 * Copyright (c) 2020 人人开源 All rights reserved.
 * <p>
 * https://www.yj.io
 * <p>
 * 版权所有，侵权必究！
 */
package com.hui.config.security.filter;

import com.hui.service.CaptchaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 验证码过滤器
 *
 * @author
 */
@Component
public class ValidateCodeFilter extends OncePerRequestFilter {

    @Autowired
    private CaptchaService captchaService;


    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                    FilterChain filterChain) throws ServletException, IOException {
//        if (request.getMethod().equals("POST") && request.getServletPath().equals("/login")) {
//            String code = request.getParameter("code");
//            try {
//                //校验验证码
//                captchaService.validate(code, (String) request.getSession().getAttribute("code"));
//            } catch (AuthenticationException e) {
//                //失败处理器
//                return;
//            }
//        }

        filterChain.doFilter(request, response);
    }
}
